package com.wdy.service.impl;

import java.util.LinkedList;
import java.util.List;

import com.wdy.dao.ParkDao;
import com.wdy.po.Park;
import com.wdy.service.ParkManager;
import com.wdy.util.PageUtil;
import com.wdy.vo.Condition;
import com.wdy.vo.Page;
import com.wdy.vo.Result;
@SuppressWarnings("unchecked")
public class ParkManagerImpl implements ParkManager {

	private ParkDao parkDao;
	
	public void setParkDao(ParkDao parkDao) {
		this.parkDao = parkDao;
	}

	
	public void savePark(Park park) {
		parkDao.save(park);
	}

	
	public void removePark(Park park) {
		parkDao.delete(park);
	}

	
	public void updatePark(Park park) {
		parkDao.attachDirty(park);
	}

	
	public Park getPark(Integer id) {
		return parkDao.findById(id);
	}


	public List<Park> listAll() {
		return parkDao.findAll();
	}

	
	public List<Park> findByExample(Park park) {
		return parkDao.findByExample(park);
	}


	public List<Park> findByLocation(String value) {
		return parkDao.findByLocation(value);
	}

	@Override
	public Result query(List<Condition> conList, Page page) {
		// TODO Auto-generated method stub
		int totalRecords = parkDao.getQueryCount(conList);
		page = PageUtil.createPage(page, totalRecords);
		List tempList = (List) parkDao.query(conList, page);
		List<Park> parks = new LinkedList<Park>();
		for(Object o: tempList){
			if(o instanceof Object[]){
				Object[] oList = (Object[]) o;
				for(Object oo: oList){
					if(oo instanceof Park){
						parks.add((Park) oo);
					}
				}
			}else{
				if(o instanceof Park){
					parks.add((Park) o);
				}
			}
		}
		return new Result(page, parks);
	}

	@Override
	public void removeParks(Object[] objects) {
		// TODO Auto-generated method stub
		parkDao.deleteBatch(objects);
	}
	

}
